<?php
class ListWidget extends Dmf_Application_Widget
{
    public function parseWidget()
    {
        if ( ! is_array( $this->getData() ) )
        {
            $this->assign( 'empty', true );
        }
        
        if ( $this->getAttr( 'checkbox' ) == 'true' )
        {
            $this->_data['headers'] = array_reverse( $this->_data['headers'] );
            $this->_data['headers'][] = '';
            $this->_data['headers'] = array_reverse( $this->_data['headers'] );
            
            foreach( $this->_data['body'] as &$data )
            {
                $xdata = isset( $data['cbx-data'] ) ? $data['cbx-data'] : null;
                
                unset( $data['cbx-data'] );
                
                $data = array_reverse( $data );
                $data[] = '<input value="' . $xdata . '" type="checkbox" />';
                $data = array_reverse( $data );
            }
        }
        else
        {
            foreach( $this->_data['body'] as &$data )
            {
                if ( ! isset( $data['cbx-data'] ) )
                {
                    continue;
                }
                
                unset( $data['cbx-data'] );
            }
        }
        
        $this->assign( 'data', $this->getData() );
    }
}